﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Miris.HumanMilkAnalyser.WPF.Shared;
using Miris.HumanMilkAnalyser.WPF.ViewModel;

namespace Miris.HumanMilkAnalyser.WPF
{
    /// <summary>
    /// Interaction logic for DiagnosticMessageReferenceSetupPage.xaml
    /// </summary>
    public partial class DiagnosticMessageReferenceSetupPage : PageBase
    {
        public DiagnosticMessageReferenceSetupPage()
        {
            InitializeComponent();
            InitializePageUnloadStoryboard();
        }

        private void CurrentPage_Loaded(object sender, RoutedEventArgs e)
        {
            // If the DataRow validation fails and DataContext changes, it causes below exception.
            // InvalidOperationException, 'DeferRefresh' is not allowed during an AddNew or EditItem transaction.
            // That's why we have to call CancelEdit() method and setup the ItemsSource in the code behind instead of XAML.
            DiagnosticMessageReferenceList.CancelEdit();
            DiagnosticMessageReferenceList.ItemsSource = ((DiagnosticMessageReferenceSetupViewModel)DataContext).DiagnosticMessageReferenceList;
        }
    }
}
